package com.offcn.entity;


import java.util.List;

public class Paging<T> {
    private int currentPage;//当前页
    private int pageSize;//每页显示的条数  写死为3条
    private int startIndex;//开始索引 startIndex = (currentPage-1)*pageSize
    private int totalCount;//总条数 查数据库select count（*）from 表名；
    private int totalPage;//总页数 （totalCount/pageSize == 0）? totalCount/pageSize : totalCount/pageSize + 1
    private int prePage;//上一页  currentPage-1
    private int nextPage;//下一页  currentPage+1
    private List<T> list;

    public Paging(String currentPage, int pageSize, int totalCount) {
        this.totalCount = totalCount;
        this.pageSize = pageSize;
        initCurrentPage(currentPage);
        initStartIndex();
        initTotalPage();
        initPrePage();
        initNextPage();
    }

    public List<T> getList() {
        return list;
    }

    public void setList(List<T> list) {
        this.list = list;
    }

    private void initCurrentPage(String currentPage) {
        if (currentPage == null){
            this.currentPage = 1;
        }else {
            this.currentPage = Integer.parseInt(currentPage);
        }
    }

    private void initStartIndex() {
        this.startIndex = (currentPage - 1) * pageSize;
    }

    private void initTotalPage() {
        this.totalPage = (totalCount % pageSize == 0) ? (totalCount / pageSize) : (totalCount / pageSize + 1);
    }

    private void initPrePage() {
        if (currentPage == 1){
            this.prePage = 1;
        }else {
            this.prePage = currentPage - 1;
        }
    }

    private void initNextPage() {
        if (currentPage == totalPage){
            this.nextPage = totalPage;
        }else {
            this.nextPage = totalPage + 1;
        }
    }



    public int getCurrentPage() {
        return currentPage;
    }

    public void setCurrentPage(int currentPage) {
        this.currentPage = currentPage;
    }

    public int getPageSize() {
        return pageSize;
    }

    public void setPageSize(int pageSize) {
        this.pageSize = pageSize;
    }

    public int getStartIndex() {
        return startIndex;
    }

    public void setStartIndex(int startIndex) {
        this.startIndex = startIndex;
    }

    public int getTotalCount() {
        return totalCount;
    }

    public void setTotalCount(int totalCount) {
        this.totalCount = totalCount;
    }

    public int getTotalPage() {
        return totalPage;
    }

    public void setTotalPage(int totalPage) {
        this.totalPage = totalPage;
    }

    public int getPrePage() {
        return prePage;
    }

    public void setPrePage(int prePage) {
        this.prePage = prePage;
    }

    public int getNextPage() {
        return nextPage;
    }

    public void setNextPage(int nextPage) {
        this.nextPage = nextPage;
    }
}
